/*This file is part of WZLibCP.

 *  WZLibCP is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

 *  WZLibCP is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

 *  You should have received a copy of the GNU General Public License
    along with WZLibCP.  If not, see <http://www.gnu.org/licenses/>.
		
	Author: calc0000
*/
#ifndef __WZLIB_WZOBJECTCOLLECTION_H
#define __WZLIB_WZOBJECTCOLLECTION_H
#include "WZLibConfig.h"

#include <vector>
#include <string>

#include "WZObject.h"
#include "WZImageProperty.h"

namespace WZLib{
	/**\brief Class that holds a collection of objects.

	This class holds a std::vector of WZObjects, and exposes
	a std::vector-like interface with which to access the
	contained elements.  However, in contrast to std::vector,
	most functions that take a WZObject as input will return that
	WZObject, allowing the possibility of chaining function calls.
	*/
	class WZObjectCollection{
	protected:
		//!The vector that holds the elements.
		std::vector<WZObject*>	_vec;
	public:
		//Constructor
		//!Constructor.
		ctor					WZObjectCollection();
		//Destructor
		//!Destructor.
		dtor					~WZObjectCollection();
		//Vector methods
		/**\brief Add an element to the collection.

		Operates similar to std::vector.push_back .

		\param obj Pointer to the WZObject to add.
		*/
		WZObject*				push_back(WZObject* obj);
		/**\brief Add an element to the collection only if it is not already contained.

		If obj is already contained in the collection, 
		the function simply returns obj.

		\param obj Pointer to the WZObject to add.
		*/
		WZObject*				push_backNODUP(WZObject* obj);
		/**\brief Alias for push_back.

		\param obj Pointer to the WZObject to add.
		*/
		WZObject*				add(WZObject* obj);
		/**\brief Gets the object at index i (or NULL if none).

		This is included to allow use of pointers to
		WZObjectCollection's.

		\param i Index of the element.
		*/
		WZObject*				at(int i);
		/**\brief Gets the object with the specified name (or NULL if none).

		\param name Name of the element to retrieve.
		*/
		WZObject*				at(std::string name);
		/**\brief Gets the object specified by obj (or NULL if none).

		\param obj Object to find.
		*/
		WZObject*				at(WZObject* obj);
		/**\brief Operator that gets the object at index i (or NULL if none).

		\param i Index of the element.
		*/
		WZObject*				operator[](int i);
		/**\brief Operator that gets the object with the specified name (or NULL if none).

		\param name Name of the element to retrieve.
		*/
		WZObject*				operator[](std::string name);
		/**\brief Operator that gets the object specified by obj (or NULL if none).

		\param obj Object to find.
		*/
		WZObject*				operator[](WZObject* obj);
		/**\brief Returns the index of obj.

		\param obj Object to find.
		*/
		int						index(WZObject* obj);
		/**\brief Empties the collection.
		*/
		void					clear();
		/**\brief Returns the size of the collection.
		*/
		unsigned int			size();
	};
};

#endif